package cate.game.role.bag.inscription;

import cate.common.table.d.GDObj;
import cate.common.table.item.inscription.row.InscriptionBaseRow;
import cate.common.util.GameResult;
import cate.game.GameBody;
import cate.game.attr.FightAttr;
import cate.game.play.support.PlayBuildContext;
import cate.game.role.Role;
import cate.game.role.bag.item.BaseBagItem;
import com.fasterxml.jackson.annotation.JsonIgnore;
import cp.solution.pattern.ICopiable;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import org.apache.commons.lang3.StringUtils;

@NoteClass("铭文")
public class Inscription extends BaseBagItem implements ICopiable<Inscription> {
    @NoteField(value = "铭文类型", detail = "决定铭文能上哪个区域")
    public int pageType;

    @NoteField(value = "铭文子类型", detail = "决定同类型铭文能上几个")
    public int detailType;

    public Inscription() {
    }

    public Inscription(Role role, int tid, long num) {
        super(role, GDObj.Type.INSCRIPTION, tid, num);
        InscriptionBaseRow baseRow = getTpl(role.getGame());
        if (baseRow == null) {
            return;
        }
        this.pageType = baseRow.pageType;
        this.detailType = baseRow.detailType;
    }

    @Override
    public Inscription copy() {
        Inscription inscription = new Inscription();
        super.copy(inscription);
        inscription.pageType = this.pageType;
        inscription.detailType = this.detailType;
        return inscription;
    }

    @Override
    public InscriptionBaseRow getTpl(PlayBuildContext ctx) {
        return ctx.inscriptionExcel().base.get(tid);
    }

    @Override
    public InscriptionBaseRow getTpl(GameBody game) {
        return getTpl(game.fight.getPlayBuildContext());
    }

    public byte getItemType() {
        return GDObj.Type.INSCRIPTION;
    }

    @JsonIgnore
    public FightAttr getPowerAttr(GameBody game) {
        FightAttr attr = new FightAttr();
        InscriptionBaseRow row = getTpl(game);
        if (row == null) {
            return attr;
        }
        // 属性铭文的属性
        InscriptionBaseRow inscriptionBaseRow = game.table.inscription.base.get(tid);
        if (inscriptionBaseRow != null) {
            if (StringUtils.isNotBlank(inscriptionBaseRow.fixedAttr)) {
                attr.add(new FightAttr(inscriptionBaseRow.fixedAttr));
            }
            if (StringUtils.isNotBlank(inscriptionBaseRow.percentAttr)) {
                attr.add(new FightAttr(inscriptionBaseRow.percentAttr));
            }
        }
        return attr;
    }

    @JsonIgnore
    public FightAttr getPowerAttr(PlayBuildContext ctx) {
        FightAttr attr = new FightAttr();
        InscriptionBaseRow inscriptionBaseRow = getTpl(ctx);
        if (inscriptionBaseRow == null) {
            return attr;
        }
        // 属性铭文的属性
        if (StringUtils.isNotBlank(inscriptionBaseRow.fixedAttr)) {
            attr.add(new FightAttr(inscriptionBaseRow.fixedAttr));
        }
        if (StringUtils.isNotBlank(inscriptionBaseRow.percentAttr)) {
            attr.add(new FightAttr(inscriptionBaseRow.percentAttr));
        }
        return attr;
    }

    public void levelUp(GameBody gameBody) {
        if (getTpl(gameBody).nextId != 0) {
            this.tid = getTpl(gameBody).nextId;
        }
    }

    public int getSkill(PlayBuildContext ctx) {
        return getTpl(ctx).skillId;
    }

}
